using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AppManagement.Repositories
{
	#region using
	using AppManagement.Models;
	#endregion
	public class PhieuKham_DichVuRepository
	{
		public static List<PhieuKham_DichVu> SelectAll()
		{
			return DataContext.Instance.PhieuKham_DichVu.ToList();
		}

		public static PhieuKham_DichVu SelectByID(int mapkdv)
		{
			return DataContext.Instance.PhieuKham_DichVu.FirstOrDefault(item => item.MaPKDV == mapkdv );
		}

		public static bool Insert(PhieuKham_DichVu obj)
		{
			try
			{
				DataContext.Instance.PhieuKham_DichVu.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int mapkdv)
		{
			try
			{
				var delitem = DataContext.Instance.PhieuKham_DichVu.FirstOrDefault(item => item.MaPKDV == mapkdv );
				DataContext.Instance.PhieuKham_DichVu.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<PhieuKham_DichVu> RetrieveByID(int mapkdv)
		{
			return (from item in DataContext.Instance.PhieuKham_DichVu where  item.MaPKDV == mapkdv  select item).ToList();
		}

		public static List<PhieuKham_DichVu> SelectByMaPK(string mapk)
		{
			var lstItem = (from item in DataContext.Instance.PhieuKham_DichVu where item.MaPK == mapk select item).ToList();
			return lstItem;
		}

		public static List<PhieuKham_DichVu> SelectByMaDV(string madv)
		{
			var lstItem = (from item in DataContext.Instance.PhieuKham_DichVu where item.MaDV == madv select item).ToList();
			return lstItem;
		}

		public static List<PhieuKham_DichVu> SelectByMaBSNV(string mabsnv)
		{
			var lstItem = (from item in DataContext.Instance.PhieuKham_DichVu where item.MaBSNV == mabsnv select item).ToList();
			return lstItem;
		}

	}
}